<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache">  <!-- HTTP 1.1 -->
    <meta http-equiv="cache-control" content="no-cache,must-revalidate">  <!-- HTTP 1.0 -->
    <meta name="renderer" content="webkit|ie-comp|ie-stand"/> <!--优先级：极速模式，兼容模式，IE模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>扬州房产测绘业务管理系统</title>
    <link rel="stylesheet" type="text/css" href="../../../libs/jeasyui-181/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../../libs/jeasyui-181/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../../libs/jeasyui-181/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../../../css/common.css">
    <script type="text/javascript" src="../../../libs/jeasyui-181/jquery.min.js"></script>
    <script type="text/javascript" src="../../../libs/jeasyui-181/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../../libs/thUtil.js"></script>
    <script type="text/javascript">

        var mainGrid = new UserContol();
        $(function () {

            //加载流程信息
            ajax.getDeployedModel(function (arr) {
                arr.push({deploymentId: "-1", name: "所有流程"});
                var allNode = {overrideId: "-1", name: "所有环节"};
                var tempList = [{overrideId: "-1", name: "所有环节"}];
                $("#processName").combobox('loadData', arr).combobox({
                    onChange: function (newVal, oldVal) {
                        for (var i = 0; i < arr.length; i++) {
                            if (arr[i].deploymentId === newVal && arr[i].deploymentId !== "-1") {
                                tempList = arr[i].nodeInfoList;
                                tempList.push(allNode);
                            }
                        }
                        $("#nodeName").combobox('loadData', tempList).combobox("setValue", "-1");
                    }
                }).combobox("setValue", "-1");
                $("#nodeName").combobox('loadData', tempList).combobox("setValue", "-1");
            });

            if (UrlParm.hasParm('text')) {
                $('h1').html(UrlParm.parm('text'));
            }
            $('#new_Link').html(button.new).linkbutton({onClick: ajax.createCase});
            $('#send_Link').html(button.send).linkbutton({onClick: ajax.sendCase});
            $('#delete_Link').html(button.delete).linkbutton({onClick: ajax.doingDelete});
            $('#handle_Link').html(button.handle).linkbutton({onClick: ajax.handle});
            $('#fast_Link').html(button.fast).linkbutton({onClick: ajax.fast});
            mygrid.init();
        });

        var ajax = {
            getList: function (param, success) {
                Network.connect(window.api.doingList, 'POST', param, function (res) {
                    if (res.code === ResponseCode.OK) {
                        success(res.data);
                    }
                });
            },
            doingDelete: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 1) {
                    Tools.confirm('是否确定重新整理数据？', function (result) {
                        if (result) {
                            Network.connect(window.api.doingDelete, "POST", rows[0], function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.alert("删除成功");
                                    mygrid.reload();
                                }
                            });
                        }
                    });
                } else {
                    Tools.alert("请选择要删除的案件");
                }
            },
            handle: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 1) {
                    window.location.href = "handle.html?todoId="+rows[0].id;
                } else {
                    Tools.alert("请选择要办理的案件");
                }
            },
            fast: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 1) {
                    Tools.alert("暂未开通该功能");
                } else {
                    Tools.alert("请选择要加急的案件");
                }
            },
            createCase: function () {
                dlg = top.$.hDialog({
                    href: window.router.createCaseFrom + '?n=' + Math.random(),
                    title: '新建案件',
                    width: 700,
                    height: 580,
                    onLoad: function () {
                        var row = mygrid.selectRow();
                        top.$('#projectNo').textbox({
                            icons: [{
                                iconCls: 'icon-add',
                                handler: function () {
                                    ajax.searchCase(top.$('#projectNo').textbox("getValue"));
                                }
                            }]
                        });
                        //行政区域
                        var param = {parentCode: "ADMIN_AREA"};
                        Network.connect(window.api.enumNoPageList, "POST", param, function (res) {
                            if (res.code === ResponseCode.OK) {
                                var arr = [];
                                var list = res.data.rows;
                                for (var i = 0; i < list.length; i++) {
                                    arr.push({id: i + 1, text: list[i].value});
                                }
                                top.$("#adminArea").combobox('loadData', arr);
                            }
                        });
                        //流程类型
                        ajax.getDeployedModel(function (arr) {
                            top.$("#flowKey").combobox('loadData', arr).combobox({
                                onChange: function (newVal, oldVal) {
                                    for (var i = 0; i < arr.length; i++) {
                                        if (arr[i].deploymentId === newVal) {
                                            top.$("#deploymentId").val(newVal);
                                            top.$('#businessName').textbox('setValue', arr[i].metaInfo.description);
                                        }
                                    }
                                }
                            });
                        });
                        //任务等级
                        var taskLevelArr = [{id: 1, text: "普件"}, {id: 2, text: "急件"}, {id: 3, text: "加急件"}];
                        top.$("#taskLevel").combobox('loadData', taskLevelArr);
                    },
                    submit: function () {
                        var isValid = top.$('#form').form("validate");
                        if (isValid) {
                            var formData = top.$("#form").serializeJson();
                            Network.connect(window.api.createCase, 'POST', formData, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    }
                });
            },
            getDeployedModel: function (methods) {
                //流程类型
                Network.connect(window.api.getDeployedModel, "POST", {}, function (res) {
                    if (res.code === ResponseCode.OK) {
                        methods(res.data.rows);
                    }
                });
            },
            resort: function () {
                Tools.confirm('是否确定重新整理数据？', function (result) {
                    if (result) {
                        Network.connect(window.api.groupReSort, 'POST', {}, function (res) {
                            if (res.code === ResponseCode.OK) {
                                Tools.show('重新整理成功');
                                mygrid.reload();
                            }
                        });
                    }
                });
            },
            searchCase: function (projectNo) {
                if (projectNo !== null && projectNo !== '') {
                    Network.connect(window.api.caseDetail, "POST", {projectNo: projectNo}, function (res) {
                        if (res.code === ResponseCode.OK) {
                            if (res.data !== null && res.data !== '') {
                                top.$('#businessKey').val(res.data.projectNo);
                                top.$('#adminArea').textbox("setValue", res.data.adminArea);
                                top.$('#projectName').textbox("setValue", res.data.projectName);
                                top.$('#businessName').textbox("setValue", res.data.businessName);
                                top.$('#fromUnit').textbox("setValue", res.data.fromUnit);
                                top.$('#contract').textbox("setValue", res.data.contract);
                            } else {
                                Tools.show("未查到有效信息")
                            }
                        }
                    })
                } else {
                    Tools.show("请填写受理号")
                }
            },
            sendCase: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 1) {
                    dlg = top.$.hDialog({
                            href: window.router.sendCaseForm + '?n=' + Math.random(),
                            title: '案件发送',
                            width: 1050,
                            height: 600,
                            onLoad: function () {
                                ajax.processDiagramPic(rows[0]);
                                //加载下一节点执行人列表
                                var paramData = {id: rows[0].id, flowKey: rows[0].flowKey, taskDefKey: rows[0].taskDefKey};
                                Network.connect(window.api.queryExecutorList, 'POST', paramData, function (res) {
                                    if (res.code === ResponseCode.OK) {
                                        //  Tools.show('添加成功');
                                        //dlg.dialog('close');
                                        // mygrid.reload();
                                        var executorList = res.data.rows;
                                        var executorArr = [];
                                        for (var i = 0; i < executorList.length; i++) {
                                            executorArr.push({
                                                u_CNAME: executorList[i].u_CNAME,
                                                uSERID: executorList[i].uSERID,
                                                status: executorList[i].u_REMARK
                                            })
                                        }
                                        top.$('#executor').combogrid({
                                            idField: 'uSERID',
                                            textField: 'u_CNAME',
                                            prompt: '请选择收件人',//输入字段描述
                                            //url:'datagrid_data.json',
                                            data: executorArr,
                                            columns: [[
                                                {field: 'u_CNAME', title: '收件人', width: 150},
                                                {
                                                    field: 'status', title: '下一环节', width: 200, halign: 'center',
                                                    align: 'center'
                                                },
                                                {field: 'Address', title: '原幢号', width: 120},
                                                {field: 'uSERID', title: '收件人id', width: 100, hidden: true}
                                            ]],
                                            fitColumns: true//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动
                                        });
                                    }
                                });
                            },
                            submit: function () {
                                var isValid = top.$('#form').form("validate");
                                if (isValid) {
                                    var formData = top.$("#form").serializeJson();
                                    var baseData = rows[0];
                                    baseData.executor = formData.executor;
                                    Network.connect(window.api.completeTask, 'POST', baseData, function (res) {
                                        if (res.code === ResponseCode.OK) {
                                            Tools.show('已发送');
                                            dlg.dialog('close');
                                            mygrid.reload();
                                        }
                                    });
                                }
                            }
                        }
                    )
                } else {
                    Tools.alert('请选择要发送的案件。');
                }
            },
            processDiagramPic: function (todo) {
                //加载流程图 高亮
                var param = {processInstanceId:todo.processInstanceId};
                Network.connect(window.api.processDiagramPic, "POST", param, function (res) {
                    if (res.code === ResponseCode.OK) {
                        top.$('#processPic').prop('src', 'data:image/png;base64,' + res.data);
                    }
                });
            }

        };

        var mygrid = {
            init: function () {
                mainGrid.dataGrid.id = 'mainGrid';
                mainGrid.dataGrid.idField = 'ID';
                //   mainGrid.dataGrid.sortName = 'USERID';
                mainGrid.dataGrid.sortOrder = 'asc';
                mainGrid.dataGrid.toolbar = '#toolbar';
                mainGrid.dataGrid.onLoadSuccess = function (data) {
                    if (data.total === 0)

                        $(".easyui-linkbutton").linkbutton();
//
                };
                mainGrid.dataGrid.loader = function (param, success, error) {
                    ajax.getList(param, success);
                };
                mainGrid.dataGrid.columns = [[
                    {
                        field: 'd',
                        title: '<img src="../../../libs/jeasyui-181/themes/icons/workflow/normal.gif">',
                        halign: 'center',
                        align: 'center',
                        width: 50,
                        formatter: function () {
//                            return '<li data-options="iconCls:\'icon-ok\'"></li>';
                            return '<img src="../../../libs/jeasyui-181/themes/icons/workflow/normal.gif">';
                        }
                    },
                    {
                        field: 'q',
                        title: '<img src="../../../libs/jeasyui-181/themes/icons/workflow/normal1.gif">',
                        halign: 'center',
                        align: 'center',
                        width: 50,
                        formatter: function () {
                            return '<img src="../../../libs/jeasyui-181/themes/icons/workflow/normal1.gif">';
                        }
                    },
                    {field: 'projectNo', title: '受理号', halign: 'center', align: 'center', width: 100},
                    {field: 'id', title: 'id', halign: 'center', align: 'center', width: 50, hidden: true},
                    {field: 'flowKey', title: '发布id', halign: 'center', align: 'center', width: 50, hidden: true},
                    {field: 'taskDefKey', title: '当前节点id', halign: 'center', align: 'center', width: 50, hidden: true},
                    {field: 'adminAreaName', title: '行政区', halign: 'center', align: 'center', width: 50},
                    {field: 'projectName', title: '项目名称', halign: 'center', align: 'left', width: 300},
                    {field: 'housePosition', title: '幢号', halign: 'center', align: 'center', width: 100},
                    {field: 'createUserName', title: '提交人', halign: 'center', align: 'center', width: 100},
                    {field: 'executorName', title: '待办人', halign: 'center', align: 'center', width: 100},
                    {field: 'executor', title: '待办人id', halign: 'center', align: 'center', width: 100, hidden: true},
                    {field: 'receiveDate', title: '到件日期', halign: 'center', align: 'center', width: 200},
                    {field: 'endDate', title: '截止日期', halign: 'center', align: 'center', width: 200},
                    {field: 'processName', title: '流程名称', halign: 'center', align: 'center', width: 150},
                    {field: 'status', title: '环节名称', halign: 'center', align: 'center', width: 100}

                ]];
                mainGrid.InitdataGrid();
            },
            reload: function () {
                $('#mainGrid').datagrid('reload');
            },
            selectRow: function () {
                return $('#mainGrid').datagrid('getSelected');
            }
        };

    </script>
    <script src="../../../libs/viewUtil.js"></script>

</head>
<body>
<div class="container-wrap">
    <div id="toolbar">
        <div class="container-tit">
            <h1></h1>
        </div>
        <div class="sreach fixed">
            <div class="input-box">
                <select class="easyui-combobox" name="processName" id="processName"
                        data-options="  width: 360,
                                            labelWidth: 80,
                                            labelPosition: 'left',
                                            required: true,
                                            label: '业务类型:',
                                            panelHeight: 'auto',
                                            valueField: 'deploymentId',
                                            textField: 'name',
                                            editable: false,"></select>
            </div>
            <div class="input-box">
                <select class="easyui-combobox" name="nodeName" id="nodeName"
                        data-options="  width: 360,
                                            labelWidth: 80,
                                            labelPosition: 'left',
                                            required: true,
                                            label: '业务环节:',
                                            panelHeight: 'auto',
                                            valueField: 'overrideId',
                                            textField: 'name',
                                            editable: false,"></select>
            </div>
            <a id="search_Link" href="#" class="easyui-linkbutton search">查询</a>
            <br/>
            <div class="input-box" style="width: 370px">
                <input type="text" id="username" name="username" class="easyui-textbox"
                       data-options="label:'受理号:',labelWidth: 80,width:350,"/>
            </div>
            <div class="input-box" style="width: 370px">
                <input type="text" id="userCname" name="userCname" class="easyui-textbox"
                       data-options="label:'业务名称:',labelWidth: 80,width:350,"/>
            </div>
            <a id="reset_Link" href="#" class="easyui-linkbutton default">重置</a>
            <div class="bar-btn" style="position: absolute;bottom: 18px;right: 8px;">
                <a id="new_Link" href="#" class="easyui-linkbutton insert">新件</a>
                <a id="handle_Link" href="#" class="easyui-linkbutton update">办理</a>
                <a id="send_Link" href="#" class="easyui-linkbutton delete">发送</a>
                <br/>
                <br/>
                <a id="fast_Link" href="#" class="easyui-linkbutton insert">加急</a>
                <a id="rollback_Link" href="#" class="easyui-linkbutton update">回退</a>
                <a id="delete_Link" href="#" class="easyui-linkbutton delete">删除</a>
            </div>
        </div>
    </div>
    <div id="mainGrid"></div>
</div>
</body>
</html>